#include <cstdio>
#include <memory>
#include "vl_future.h"

using namespace VL;

int main(int argc, const char ** argv) {
	auto futurePtr = VLFuture::newTypeFuture<int, int>();
	futurePtr->then([](const std::shared_ptr<int>& dataPtr) {
		printf("then 1 : %d\n", *dataPtr);
	})->error([](const std::shared_ptr<int>& errorPtr) {
		printf("error 1 : %d\n", *errorPtr);
	})->complete([]() {
		printf("completed 1\n");
	});

	futurePtr->chain<std::string, std::string>([](const std::shared_ptr<int>& dataPtr) {
		auto newFuturePtr = VLFuture::newTypeFuture<std::string, std::string>();
		newFuturePtr->setData("hello world");
		return newFuturePtr;
	})->then([](const std::shared_ptr<std::string>& dataPtr) {
		printf("then 2 : %s\n", dataPtr->c_str());
	})->chain<bool, bool>([](const std::shared_ptr<std::string>& dataPtr) {
		auto newFuturePtr = VLFuture::newTypeFuture<bool, bool>();
		newFuturePtr->setData(true);
		return newFuturePtr;
	})->then([](const std::shared_ptr<bool>& dataPtr) {
		printf("then 3 : %s\n", (*dataPtr) ? "true" : "false");
	});

	futurePtr->setData(1);

	// auto futurePtr = FutureBuilder::build<int, int>();
	// auto futurePtr2 = futurePtr->as<int, int>()->then([](const std::shared_ptr<int>& dataPtr) {
	// 	printf("then 1 : %d\n", *dataPtr);
	// })->then([](const std::shared_ptr<int>& dataPtr) {
	// 	printf("then 2 : %d\n", *dataPtr);
	// })->chain<std::string, std::string>([](const std::shared_ptr<int>& dataPtr) {
	// 	printf("make chain: %d \n", *dataPtr);
	// 	auto futurePtr = FutureBuilder::build<std::string, std::string>();
	// 	return futurePtr->as<std::string, std::string>();
	// })->then([](const std::shared_ptr<std::string>& dataPtr) {
	// 	printf("then 3 : %s\n", dataPtr->c_str());
	// });
	// futurePtr->as<int, int>()->setData(1);
	printf("done\b");
	return 0;
}
